﻿// Study1006.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
// 第十章 STL和泛型设计 列表容器

#include <iostream>
#include<list>
#include<string>
using namespace std;
int main()
{
	string names1[] = { "Alice", "Helen", "Lucy", "Susan" };
    string names2[] = { "Bob", "David", "Levin", "Mike" };  
    list<string> s1(names1, names1+4);
    list<string> s2(names2, names2+4);

    s2.splice(s2.end(), s1, s1.begin());//{ "Bob", "David", "Levin", "Mike","Alice" }
	auto iter1 = s1.begin();//{    "Helen", "Lucy", "Susan" }   "Helen"
    advance(iter1, 2);//{    "Helen", "Lucy", "Susan" }   "Susan"
	auto iter2 = s2.begin();//{ "Bob", "David", "Levin", "Mike","Alice" }   "Bob"
    ++iter2;//{ "Bob", "David", "Levin", "Mike","Alice" }   "David"
	auto iter3 = iter2;
    advance(iter3, 2);//{ "Bob", "David", "Levin", "Mike","Alice" }   "Mike"
    s1.splice(iter1, s2, iter2, iter3);//{"Helen", "Lucy","David", "Levin","Susan" }

    copy(s1.begin(), s1.end(), ostream_iterator<string>(cout, " "));
    cout << endl;
    copy(s2.begin(), s2.end(), ostream_iterator<string>(cout, " "));
    cout << endl;

    return 0;

}

